/* 
 * File:   BulletSimulatorThread.h
 * Author: jcrada
 *
 * Created on December 3, 2008, 9:37 PM
 */

#ifndef _BULLETSIMULATORTHREAD_H
#define	_BULLETSIMULATORTHREAD_H
#include <QtCore/QThread>
#include "BulletSimulator.h"
namespace jcrada {

    class BulletSimulatorThread : public QThread {

        Q_OBJECT
    public:
        enum eSimulationMode {
            SM_FREE = 0, SM_EVALUATION,
        };
    public slots:
        virtual void notify( );
        virtual void stop( );
        virtual void step( bool& ground_was_hit );
        virtual void step();
        virtual void setBehaviorEnabled( bool enabled );
        virtual void setBehaviorOnGround( bool on_ground );
        virtual void setEvaluationTimeInSeconds( int seconds );
        virtual void setSimulationMode( int mode );

    signals:
        void changedBehaviorEnabled( bool );
        void changedBehaviorOnGround( bool );
        void changedEvaluationTimeInSeconds( int );
        void changedSimulationMode( int );

    public:

        BulletSimulatorThread( );
        virtual ~BulletSimulatorThread( );

        virtual void run( );
        virtual void evaluate( Creature& creature );

        virtual void setSimulator( BulletSimulator* _simulator );

        virtual BulletSimulator& getSimulator( ) const {
            return *this->_simulator;
        }

        virtual bool isBehaviorEnabled( ) const {
            return _behavior_enabled;
        }

        virtual bool isBehaviorOnGround( ) const {
            return _behavior_on_ground;
        }

        virtual bool isEvaluationTimeEnabled( ) const {
            return _evaluation_time_enabled;
        }

        virtual int getEvaluationTimeInSeconds( ) const {
            return _evaluation_time_in_seconds;
        }

        virtual eSimulationMode getSimulationMode( ) const {
            return this->_simulation_mode;
        }
    protected:
        virtual void _run_free( );
        virtual void _run_evolution( );
        virtual void waitForTimestepsCompletion( int time_elapsed_ms );

    private:
        BulletSimulator* _simulator;
        bool _behavior_enabled;
        bool _behavior_on_ground;
        bool _evaluation_time_enabled;
        int _evaluation_time_in_seconds;
        eSimulationMode _simulation_mode;
    };

}

#endif	/* _BULLETSIMULATORTHREAD_H */

